//package cn.e3mall.service.impl;
//
//import cn.e3mall.mapper.TbItemMapper;
//import cn.e3mall.pojo.TbItem;
//import cn.e3mall.pojo.TbItemExample;
//import cn.e3mall.service.ItemService;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Service;
//
//import java.util.List;
//
//@Service
//public class ItemServiceImpl implements ItemService {
//
//    @Autowired
//    private TbItemMapper itemMapper;
//
//    @Override
//    public TbItem getItemById(long itemId) {
//        //根据主jian查询
//        TbItem tbItem = itemMapper.selectByPrimaryKey(itemId);
//
//        TbItemExample example = new TbItemExample();
//        TbItemExample.Criteria criteria = example.createCriteria();
//        //设置条件查询
//        criteria.andIdEqualTo(itemId);
////        itemMapper.selectByExample(example);
//        List<TbItem>list = itemMapper.selectByExample(example);
//        if (list != null && list.size() >0){
//            return list.get(0);
//        }
//
//
//        return null;
//    }
//}
package cn.e3mall.service.impl;

import cn.e3mall.mapper.TbItemMapper;
import cn.e3mall.pojo.TbItem;
import cn.e3mall.pojo.TbItemExample;
import cn.e3mall.service.ItemService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


//管理商品service
@Service
public class ItemServiceImpl implements ItemService {

    @Autowired
    private TbItemMapper itemMapper;

    @Override
    public TbItem getItemById(long itemId) {
        TbItem tbItem = itemMapper.selectByPrimaryKey(itemId);

        TbItemExample example = new TbItemExample();
        TbItemExample.Criteria criteria = example.createCriteria();
        criteria.andIdEqualTo(itemId);
        List<TbItem>list = itemMapper.selectByExample(example);

        if (list != null){
            return list.get(0);

        }
        return null;
    }
}
